#!/usr/bin/env python
# -*- coding:utf-8 -*-

class AbstractFactory(object):
    def getShape(self):
        return Shape()

    def getColor(self):
        return Color()


class Shape(AbstractFactory):
    #create  based on class name
    @staticmethod
    def shapeFactory(type):
        #return eval(type + "0")
        if type == "Circle":
            return Circle()
        if type == "Square":
            return Square()
        assert 0 , "Bad shape creation: " + type


class Circle(Shape):
    def __init__(self):
        self.name = "Circle"

    def draw(self):
        print(self.name + " draw")

    def erase(self):
        print(self.name + " erase")


class Square(Shape):
    def __init__(self):
        self.name = "Square"

    def draw(self):
        print(self.name + ' draw')

    def erase(self):
        print(self.name + " erase")

class Color(AbstractFactory):
    #create  based on class name
    @staticmethod
    def colorFactory(type):
        #return eval(type + "0")
        if type == "Red":
            return Red()
        if type == "Green":
            return Green()
        assert 0 , "Bad color creation: " + type


class Red(Color):
    def __init__(self):
        self.name = "Red"

    def padding(self):
        print(self.name + " padding")

    def reset(self):
        print(self.name + " reset")


class Green(Color):
    def __init__(self):
        self.name = "Green"

    def padding(self):
        print(self.name + " padding")

    def reset(self):
        print(self.name + " reset")


if __name__ == '__main__':
    abstractFactory = AbstractFactory()
    types = Shape.__subclasses__()
    for type in types:
        circle = abstractFactory.getShape().shapeFactory(type.__name__)
        circle.draw()
        circle.erase()
    types = Color.__subclasses__()
    for type in types:
        color = abstractFactory.getColor().colorFactory(type.__name__)
        color.padding()
        color.reset()